<template>
  <div class="app-container add">
    <CommonHeader title="采购入库单明细" :isShowBack="true" />
    <div class="add-wrap">
      <div class="form-box">
        <div class="form-title">物料信息</div>
        <el-form
          :model="formData"
          ref="formData"
          :rules="rules"
          inline-message
          label-width="0"
          label-position="left"
        >
          <el-form-item prop="productCode">
            <div class="form-item">
              <div class="label">
                <span class="required"></span>物料编码
                <img
                  src="@/assets/images/scan02.png"
                  alt=""
                  class="scan"
                  @click="handleScan('material')"
                />
              </div>
              <div class="select-wrap" @click="selectMaterial">
                <span class="val" v-if="formData.productCode">{{
                  formData.productCode
                }}</span>
                <span class="txt" v-else>请选择</span>
                <i class="el-icon-arrow-down down-icon"></i>
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="productName">
            <div class="form-item">
              <div class="label">
                <span class="required"></span>物料名称
                <!-- <img src="@/assets/images/scan02.png" alt="" class="scan" @click="handleScan('material')"> -->
              </div>
              <div class="select-wrap" @click="selectMaterial">
                <span class="val" v-if="formData.productName">{{
                  formData.productName
                }}</span>
                <!-- <span class="txt" v-else>请选择</span> -->
                <!-- <i class="el-icon-arrow-down down-icon"></i> -->
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="skuId">
            <div class="form-item">
              <div class="label">特征参数</div>
              <div class="info-wrap" @click="skuDialog">
                <span class="val" v-if="formData.skuName">{{
                  this.formData.skuName
                }}</span>
                <span class="code" v-else>请选择</span>
                <i class="el-icon-arrow-down down-icon"></i>
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="planAmount">
            <div class="form-item">
              <div class="label">计划数量</div>
              <div class="info-wrap" v-number>
                <input
                  type="text"
                  v-model="formData.planAmount"
                  placeholder="请输入"
                />
              </div>
            </div>
          </el-form-item>
          <!--  <el-form-item prop="actualAmount">
                        <div class="form-item">
                            <div class="label">实际数量</div>
                            <div class="info-wrap">
                                <input type="text"  v-model="formData.actualAmount" placeholder="请输入" />
                            </div>
                        </div>
                    </el-form-item> -->
          <el-form-item prop="">
            <div class="form-item">
              <div class="label">是否批次管理</div>
              <div class="info-wrap">
                {{ formData.isBatchMag ? "是" : "否" }}
              </div>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <!--  -->
      <div class="model-title">批次信息</div>
      <div class="form-box">
        <div class="tab-box">
          <div class="tab-hd">
            <span
              class="item"
              :class="{ active: current === 1 }"
              @click="changeTab(1)"
              >新增批次</span
            >
            <span
              class="item"
              v-if="formData.isBatchMag"
              :class="{ active: current === 2 }"
              @click="changeTab(2)"
              >选择批次</span
            >
          </div>
          <div class="tab-bd">
            <div class="con" v-if="current === 1">
              <el-form
                :model="addBatchForm"
                ref="addBatchForm"
                :rules="addBatchRules"
                inline-message
                label-width="0"
                label-position="left"
              >
                <el-form-item prop="receiveMaterialNum">
                  <div class="form-item">
                    <div class="label">
                      <span class="required"></span>入库数量
                    </div>
                    <div class="info-wrap">
                      <el-input
                        class="myInput"
                        type="text"
                        v-model="addBatchForm.receiveMaterialNum"
                        placeholder="请输入"
                        @focus="selectAllText"
                        @blur="
                          () => {
                              changeNum(addBatchForm.receiveMaterialNum, 'receiveMaterialNum');
                          }"
                      />
                    </div>
                  </div>
                </el-form-item>
                <el-form-item
                  prop="everyBatchNum"
                  v-if="formData.isBatchMag"
                >
                  <div class="form-item">
                    <div class="label">
                      <span class="required"></span>每批数量
                    </div>
                    <div class="info-wrap">
                      <el-input
                        class="myInput"
                        type="number"
                        v-model="addBatchForm.everyBatchNum"
                        placeholder="请输入"
                        @focus="selectAllText"
                        @blur="() => {changeNum(addBatchForm.everyBatchNum, 'everyBatchNum');}"
                      />
                    </div>
                    <!-- @input="(val) => {changeNum(val, 'everyBatchNum');}" -->
                  </div>
                </el-form-item>
                <el-form-item
                  prop="batchCodeNum"
                  v-if="formData.isBatchMag"
                >
                  <div class="form-item">
                    <div class="label">
                      <span class="required"></span>批次码个数
                    </div>
                    <div class="info-wrap">
                      <el-input
                        class="myInput"
                        type="number"
                        v-model="addBatchForm.batchCodeNum"
                        placeholder="请输入"
                        @focus="selectAllText"
                        @blur="() => {changeNum(addBatchForm.batchCodeNum, 'batchCodeNum');}"
                      />
                    </div>
                    <!-- @input="(val) => {changeNum(val, 'batchCodeNum');}" -->
                  </div>
                </el-form-item>
                <el-form-item prop="rule" v-if="formData.isBatchMag">
                  <div class="form-item" @click="addBatchRule">
                    <div class="label">
                      <span class="required"></span>批次规则
                    </div>
                    <div class="select-wrap">
                      <span class="val" v-if="addBatchForm.rule">{{
                        addBatchForm.rule
                      }}</span>
                      <span class="txt" v-else>请选择</span>
                      <i class="el-icon-arrow-down down-icon"></i>
                    </div>
                  </div>
                </el-form-item>
                <el-form-item prop="materialQuality">
                  <div class="form-item" prop="materialQuality">
                    <div class="label">批次品质</div>
                    <el-select
                      v-model="addBatchForm.materialQuality"
                      filterable
                      placeholder="请选择"
                      style="width: 50%"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </div>
                </el-form-item>
                <div class="form-item">
                  <div class="label">批次备注</div>
                  <div class="info-wrap">
                    <input
                      type="text"
                      v-model="addBatchForm.remark"
                      placeholder="请输入备注内容"
                    />
                  </div>
                </div>
              </el-form>
            </div>
            <div class="con" v-if="current === 2">
              <el-form
                :model="selectBatchForm"
                ref="selectBatchForm"
                :rules="selectBatchRules"
                inline-message
                label-width="0"
                label-position="left"
              >
                <el-form-item prop="realNum">
                  <div class="form-item" props="realNum">
                    <div class="label">
                      <span class="required"></span>入库数量
                    </div>
                    <div class="info-wrap" v-number>
                      <input
                        type="number"
                        v-model="selectBatchForm.realNum"
                        placeholder="请输入"
                        @focus="selectAllText"
                      />
                    </div>
                  </div>
                </el-form-item>
                <el-form-item prop="barCode">
                  <div class="form-item">
                    <div class="label">
                      <span class="required"></span>批次号
                      <img
                        src="@/assets/images/scan02.png"
                        alt=""
                        class="scan"
                        @click="handleScan('batch')"
                      />
                    </div>
                    <!-- <div class="info-wrap">
                      <input
                        readonly
                        type="text"
                        v-model="selectBatchForm.barCode"
                        placeholder="请输入"
                        @click="toDetail()"
                      />
                    </div> -->
                    <div class="select-wrap" @click="toDetail()">
                      <span class="val" v-if="selectBatchForm.barCode">{{ selectBatchForm.barCode  }}</span>
                      <span class="txt" v-else>请选择</span>
                      <i class="el-icon-arrow-down down-icon"></i>
                    </div>
                  </div>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="model-footer-wrap">
      <van-button
        type="primary"
        block
        round
        color="#548af1"
        size="normal"
        :loading="btnLoading"
        loading-text="正在提交..."
        @click="submitAdd"
        >提交</van-button
      >
    </div>
    <!-- 时间选择 -->
    <van-calendar
      v-model="dateShow"
      color="#548AF1"
      :min-date="minDate"
      @confirm="onDateConfirm"
    />
    <!-- BatchRule -->
    <BatchRule
      :addBatchVisible="addBatchVisible"
      :addBatchParams="formData"
      @confirmRule="confirmBatchRule"
      @closeDialog="closeDialog"
    />
    <!--物料特征参数选择弹窗 -->
    <ChoiceSpecificParamsDialog
      v-if="choiceSpecificParamstVisible"
      :show="choiceSpecificParamstVisible"
      :material-code="this.formData.productCode"
      :sku-id="this.formData.skuId || 0"
      @confirm="confirmChoiceSpecificParams"
      @cancel="cancelChoiceSpecificParams"
    />
    <bar-code-list
      :data="barCodeDataList"
      :show.sync="barCodeShow"
      @confirm="confirm"
    ></bar-code-list>
  </div>
</template>
<script>
import barCodeList from "../batch/components/barCodeList"
import ChoiceSpecificParamsDialog from "@/components/ChoiceSpecificParamsDialog/index.vue";
import CommonHeader from "@/components/CommonHeader";
import BatchRule from "@/components/BatchRule";
import {
  addMaterialDetails,
  newAddBarCode,
  getNewAddBarCodeProgress,
  inventoryList,
  getWorkerOrderCodeList,
  getMaterialInfo,
  getStockInAndOutById,
} from "@/api/inventory";
import { Toast } from "vant";
export default {
  components: { CommonHeader, BatchRule, ChoiceSpecificParamsDialog,barCodeList },
  data() {
    var validateBatchCodeNum = (rule, value, callback) => {
      console.log(value, "value");
      if (!value && value !== 0) {
        callback(new Error("该项为必填！"));
      } else {
        console.log(value, "intValue");
        if (value<=0) {
          callback(new Error("不能小于等于0"));
        } else {
          callback();
        }
      }
    };
    return {
      showNum: false,
      numTitle: '',
      dialogNumber: '',
      numberType: '',
      current: 1,
      btnLoading: false,
      options: [
        {
          value: "1",
          label: "合格",
        },
        {
          value: "0",
          label: "不合格",
        },
      ],
      formData: {
        productCode: "",
        planAmount: "",
        actualAmount: "",
        skuId: "",
        skuCode: "",
        skuName: "",
      },
      rules: {
        productCode: [{ required: true, message: "请选择", trigger: "blur" }],
      },
      dateShow: false,
      minDate: new Date(2010, 0, 1),
      addBatchRules: {
        batchCodeNum: [
          {
            required: true,
            validator: validateBatchCodeNum,
            trigger: ["blur", "change"],
          },
        ],
        receiveMaterialNum: [
          { required: true, message: "请选择", trigger: ["blur", "change"] },
        ],
        everyBatchNum: [
          {
            required: true,
            validator: validateBatchCodeNum,
            trigger: ["blur", "change"],
          },
        ],
        rule: [{ required: true, message: "请选择", trigger: "blur" }],
      },
      addBatchForm: {
        batchCodeNum: "",
        receiveMaterialNum: "",
        everyBatchNum: "",
        rule: "",
        materialQuality: "1",
      },
      selectBatchForm: {
        realNum: "",
        barCode: "",
      },
      selectBatchRules: {
        realNum: [
          {
            required: true,
            validator: validateBatchCodeNum,
            trigger: ["blur", "change"],
          },
        ],
        barCode: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      addBatchParams: {},
      addBatchVisible: false,
      choiceSpecificParamstVisible: false,
      barCodeShow: false,
      barCodeDataList: [],
    };
  },
  watch: {},
  created() {
    if (this.$route.query && this.$route.query.materialInfo) {
      let materialInfo = JSON.parse(this.$route.query.materialInfo);
      this.formData.productCode = materialInfo.code;
      this.formData.productName = materialInfo.name;
      this.formData.isBatchMag = materialInfo.isBatchMag;
      this.formData.skuName = materialInfo.skuName;
      this.formData.skuId = materialInfo.skuId;
      this.formData.skuCode = materialInfo.skuCode;
      this.formData.planAmount = materialInfo.planAmount;
      this.formData.materialType = materialInfo.materialType;
      this.formData.type = materialInfo.type;
    }
    this.initSelectBatchForm();
  },
  methods: {
    selectAllText(event) {
        event.target.select();
    },
    changeNum(val, type) {
      if (!val) return;
      // 防抖
      clearTimeout(this.debounceTimer);
      this.debounceTimer = setTimeout(() => {
        switch (type) {
          case "receiveMaterialNum":
            if (this.addBatchForm.everyBatchNum) {
              this.addBatchForm.batchCodeNum = Math.ceil(
                val / this.addBatchForm.everyBatchNum
              );
            } else if (
              !this.addBatchForm.everyBatchNum &&
              this.addBatchForm.batchCodeNum
            ) {
              this.addBatchForm.everyBatchNum =
                val / this.addBatchForm.batchCodeNum;
            }
            break;

          case "everyBatchNum":
            if (this.addBatchForm.receiveMaterialNum) {
              this.addBatchForm.batchCodeNum = Math.ceil(
                this.addBatchForm.receiveMaterialNum / val
              );
            } else if (
              !this.addBatchForm.receiveMaterialNum &&
              this.addBatchForm.batchCodeNum
            ) {
              this.addBatchForm.receiveMaterialNum =
                val * this.addBatchForm.batchCodeNum;
            }

            break;
          case "batchCodeNum":
            if (this.addBatchForm.everyBatchNum) {
              this.addBatchForm.receiveMaterialNum =
                val * this.addBatchForm.everyBatchNum;
            } else if (
              !this.addBatchForm.everyBatchNum &&
              this.addBatchForm.receiveMaterialNum
            ) {
              this.addBatchForm.everyBatchNum =
                this.addBatchForm.receiveMaterialNum / val;
            }
            break;

          default:
            break;
        }
      }, 500);
    },
    initSelectBatchForm() {
      const selecData = JSON.parse(localStorage.getItem("selectData")) || {};
      console.log(selecData.stockMaterialDetaiList, '99999--')
      if (selecData.stockMaterialDetaiList) {
        this.current = 2;
        this.selectBatchForm = selecData;
        this.selectBatchForm.barCode = selecData.stockMaterialDetaiList?.barCode;
        this.stockMaterialDetaiList = [selecData.stockMaterialDetaiList];
        if(this.stockMaterialDetaiList.length > 0) {
          this.stockMaterialDetaiList.forEach(item => {
            item.realNum = selecData.realNum
          })
        }
      }
    },
    toDetail() {
      localStorage.setItem("selectData", JSON.stringify(this.selectBatchForm));
      const obj = {
        ...JSON.parse(this.$route.query.materialInfo),
        skuId:this.formData.skuId,
        skuCode:this.formData.skuCode,
        skuName:this.formData.skuName,
        planAmount:this.formData.planAmount,
      }
      this.$router.push({
        path: "/materialDetailSelect",
        query: {
          id: this.$route.query.id,
          orderNumber: this.$route.query.orderNumber,
          warehouseCode: this.$route.query.warehouseCode,
          materialInfo: JSON.stringify(obj),
          skuId:this.formData.skuId,
          type:'allocationDetailForm'
        },
      });
    },
    confirm(data){
        this.stockMaterialDetaiList = data
        console.log('this.stockMaterialDetaiList',this.stockMaterialDetaiList)
        this.selectBatchForm.barCode = data[0].barCode
    },
    confirmChoiceSpecificParams(data) {
      this.formData.skuId = data.skuId;
      this.formData.skuCode = data.skuCode;
      this.formData.skuName = data.skuName;
      this.choiceSpecificParamstVisible = false;
    },
    cancelChoiceSpecificParams() {
      this.choiceSpecificParamstVisible = false;
    },
    skuDialog() {
      if (!this.formData.productCode) {
        Toast("请先选择物料");
        return;
      }
      this.choiceSpecificParamstVisible = true;
    },
    // 提交新增保存
    async submitAdd() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          // 判读是新增批次还是选择批次
          if (this.current === 2) {
            this.$refs.selectBatchForm.validate((valid) => {
              if (valid) {
                this.submitAddMaterialDetails();
              } else {
                this.btnLoading = false;
              }
            });
          } else {
            this.submitAddBatch();
          }
        }
        // this.btnLoading = false;
      });
    },
    // 调用物料明细新增接口
    async submitAddMaterialDetails() {
      const stockMaterialDetaiList = {};
      this.stockMaterialDetaiList.map(item=>{
        item.realNum = item.realNum || this.selectBatchForm.realNum
      })
      const materialDetails = {
        ...this.formData,
        materialQuality: this.addBatchForm.materialQuality,
        stockMaterialDetaiList: this.stockMaterialDetaiList || [],
      };
      const param = {
        id: this.$route.query.id || null,
        materialDetails: [materialDetails],
      };
      console.log(param, '--9')
      addMaterialDetails(param).then((res) => {
        const data = res.data;
        if (data.code == "200") {
          this.btnLoading = false;
          Toast("新增物料明细成功");
          //  this.$router.back()
          localStorage.removeItem("selectData");
          this.$router.push({
            path: "/allocationDetail",
            query: {
              id: this.$route.query.id,
            },
          });
        } else {
          this.btnLoading = false;
          Toast(data.message || "新增物料明细失败");
        }
      });
    },
    // 提交保存批次新增，再查询批次号列表
    async submitAddBatch() {
      this.$refs.addBatchForm.validate((valid) => {
        if (valid) {
          // 判断物料是否是批次管理
          if (!this.formData.isBatchMag) {
            this.stockMaterialDetaiList = [
              {
                realNum: this.addBatchForm.receiveMaterialNum || 0,
                inventoryDetailId: "",
                skuId: this.formData.skuId || 0,
                skuCode: this.formData.skuCode,
                skuName: this.formData.skuName,
                remark: this.addBatchForm.remark,
                materialQuality: this.addBatchForm.materialQuality,
              },
            ];
            this.submitAddMaterialDetails();
            return;
          }
          // 提交保存批次
          let orderNumber = this.$route.query.orderNumber; // 入库单号
          let supplierCode = "";
          let relateOrders = ""; //关联单号
          const param = {
            skuId: this.formData.skuId || 0,
            batchSpecs: this.formData.batchSpecs || "", // 批次规格
            batchCount: +this.addBatchForm.receiveMaterialNum,
            barCode: this.hdCreatBarCode(),
            count: +this.addBatchForm.everyBatchNum,
            num: +this.addBatchForm.batchCodeNum,
            relateNumber: orderNumber,
            materialCode: this.formData.productCode,
            numberRuleId: this.addBatchRuleData.type,
            ruleDetail: JSON.stringify(this.ruleFormItems),
            supplierCode,
            numberMap: {
              6: this.formData.productCode ?? "",
              12: supplierCode ?? "",
              13: relateOrders,
              15: orderNumber,
            },
            relatedMap: {
              supplier: supplierCode ?? "",
              purchase: relateOrders,
              purchaseReceipt: orderNumber,
            },
            moduleType: "otherInStockBatch",
            remarks: this.addBatchForm.remark,
          };
          newAddBarCode(param).then((res) => {
            console.log(res, "===8");
            const data = res.data;
            if (data.code == "200") {
              this.getNewAddBarCodeProgress(orderNumber)
              // getNewAddBarCodeProgress({
              //   relatedNumber: orderNumber,
              //   type: "otherInStockBatch",
              // }).then((res) => {
              //   if (res.data.code == "200") {
              //     const {
              //       progress,
              //       executionDescription,
              //       code: innnerCode,
              //     } = JSON.parse(res.data.message);
              //     if (innnerCode === "200") {
              //       this.percentage = Number((progress * 100).toFixed(0));
              //       console.log(this.percentage, "this.percentage");
              //       this.getBatchCodeList();
              //     } else {
              //       this.btnLoading = false;
              //       Toast(executionDescription || "批次新增异常！");
              //     }
              //   }
              // });
            }
          });
        } else {
          this.btnLoading = false;
        }
      });
    },
    async getNewAddBarCodeProgress(orderNumber){
      const result = await getNewAddBarCodeProgress({
        relatedNumber: orderNumber,
        type: "otherInStockBatch",
      })
      const {data,code,message} = result.data
      if(code == 200){
        const {
          progress,
          executionDescription,
          code: innnerCode,
          executionStatus
        } = JSON.parse(message);
        
        if (innnerCode === "200") {
          if(executionStatus){
            this.getBatchCodeList();
          }else{
            this.getNewAddBarCodeProgress(orderNumber)
          }
        }else {
          Toast(executionDescription || "批次新增异常！");
        }
      }
    },
    // 新增完成后获取批次信息
    async getBatchCodeList() {
      const {
        data: {
          code,
          data: { records = [] },
        },
      } = await getWorkerOrderCodeList({
        current: 1,
        size: 99999,
        materialCode: this.formData.productCode,
        relateNumber: this.$route.query.orderNumber,
        skuId: this.formData?.skuId || 0,
      });
      records.map((i) => (i.isNewAdd = true));
      if (code === "200") {
        records.map((item) => {
          item.remark = this.addBatchForm.remark;
          item.materialQuality = this.addBatchForm.materialQuality;
        });
        this.stockMaterialDetaiList = records;
        this.submitAddMaterialDetails();
      }
    },
    hdCreatBarCode() {
      const keys = Object.keys(this.addBatchRuleData).filter((i) =>
        i.startsWith("prefix-")
      );
      keys.sort((a, b) => {
        return Number(a.split("-")[1]) - Number(b.split("-")[1]);
      });
      console.log(keys, "keys");
      keys.forEach((i, index) => {
        console.log(i, index);
        this.ruleFormItems[index].value = this.addBatchRuleData[i];
        console.log(this.addBatchRuleData[i], "this.addBatchForm[i]");
      });
      return keys.reduce(
        (cSum, cItem) => cSum + this.addBatchRuleData[cItem],
        ""
      );
    },
    // 选择批次规则弹窗
    addBatchRule() {
      if (!this.addBatchForm.receiveMaterialNum) {
        Toast("请先输入入库数量信息");
        return;
      }
      this.addBatchVisible = true;
    },
    // 关闭批次规则弹窗
    closeDialog() {
      this.addBatchVisible = false;
    },
    onUserConfirm(val) {
      this.formData.approver = val.userName;
      this.userModalShow = false;
    },
    formatDate(date) {
      return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
    },
    onDateConfirm(date) {
      this.dateShow = false;
      this.formData.date = this.formatDate(date);
    },
    changeTab(val) {
      this.current = val;
      this.selectBatchForm = {
        realNum: "",
        barCode: "",
      }
      localStorage.removeItem("selectData");
    },
    // 选择物料
    selectMaterial() {
      this.$router.push({
        path: "/materialSelect",
        query: {
          id: this.$route.query.id,
          orderNumber: this.$route.query.orderNumber,
          warehouseCode: this.$route.query.warehouseCode,
          type: "allocationDetail",
        },
      });
    },
    // 批次号扫码
    async handleScan(type) {
      // 生产环境和开发环境
      const that = this;
      if (process.env.NODE_ENV === "production") {
        window.flutter_inappwebview.callHandler("qrCode").then((res) => {
          if (!res) return;
          if (type === "batch") {
            that.getBatchCode(res);
          } else {
            that.materialScanInfo(res);
          }
        });
      } else {
        if (type === "batch") {
          that.getBatchCode("CK2023072000187");
        } else {
          that.materialScanInfo("KKKL233");
        }
      }
    },
    // 物料编码扫码获取物料信息
    async materialScanInfo(id) {
      const result = await getMaterialInfo({ code: id });
      const { code, data = {}, message } = result.data || {};
      if (+code === 200) {
        console.log(data, "====d2ata");
        if(!data.code){
          Toast('扫描得物料不正确')
          return
        }
        this.formData.productCode = data.code;
        this.formData.productName = data.name;
        this.formData.isBatchMag = data.isBatchMag;
        this.$forceUpdate();
      }else{
        Toast('扫描得物料不正确')
      }

      console.log(this.formData, "---this.formData");
    },
    // 批次号获取物料信息
    async getBatchCode(barCode) {
      const param = {
        materialCode: this.formData.productCode,
        skuId: this.formData.skuId || 0,
        barCode: barCode,
        warehouseCode: this.$route.query.warehouseCode,
      };
      const result = await inventoryList(param);
      const { code, data = {}, message } = result.data || {};
      if (+code === 200) {
        const { records = [] } = data;
        this.barCodeDataList = records.filter(i=>i.stockLocationQuantity != 0);
        if (records.length > 0) {
          this.barCodeShow = true;
        } else {
          Toast("扫描的批次不存在");
          return;
        }
        this.stockMaterialDetaiList = records.map((item) => {
          return {
            realNum: this.selectBatchForm.realNum,
            inventoryDetailId: item.inventoryDetailId,
            skuId: item.skuId,
            skuCode: item.skuCode,
            skuName: item.skuName,
            materialQuality: item.materialQuality,
          };
        });
        if (records.length == 0) {
          Toast("仓库内此物料无此批次!");
        } else {
          this.selectBatchForm.barCode = barCode;
        }
        console.log(records, "====records");
      } else {
        Toast("获取失败");
      }
    },
    // 保存批次规则
    confirmBatchRule(data, ruleFormItems) {
      console.log(data, "====data");
      this.addBatchRuleData = data;
      this.addBatchForm.rule = "已选";
      this.ruleFormItems = ruleFormItems;
      console.log(this.addBatchForm, "====this.addBatchForm");
      this.addBatchVisible = false;
    },
  },
};
</script>

<style lang="scss" >
.add-wrap {
  .el-form-item__error {
    position: absolute !important;
    top: 25px;
    right: 30px;
  }
  .el-form-item {
    margin-bottom: 0 !important;
  }
  .el-input__inner {
    border: none !important;
    text-align: right !important;
    padding-right: 20px !important;
  }
  .el-input__suffix {
    right: -6px;
  }
}
</style>
<style lang="scss" scoped>
.header-top {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
}
.add-wrap {
  padding-top: 44px;
  padding-bottom: 80px;
  .model-title {
    font-size: 16px;
    margin: 0 7px;
    display: flex;
    align-items: center;
    border-bottom: 1px #f3f3f3 solid;
    position: relative;
    padding-left: 8px;
    margin: 12px 19px 0;
    &::before {
      content: "";
      width: 4px;
      height: 14px;
      background-color: #548af1;
      position: absolute;
      left: 0;
      top: 4px;
    }
  }
  .form-box {
    margin: 12px 12px 0;
    background-color: #ffffff;
    border-radius: 4px;
    .form-title {
      font-size: 16px;
      margin: 0 7px;
      height: 40px;
      display: flex;
      align-items: center;
      border-bottom: 1px #f3f3f3 solid;
      position: relative;
      padding-left: 8px;
      &::before {
        content: "";
        width: 4px;
        height: 14px;
        background-color: #548af1;
        position: absolute;
        left: 0;
        top: 13px;
      }
    }
    .form-item {
      margin: 0 7px;
      padding: 0 7px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px #f3f3f3 dotted;
      font-size: 13px;
      color: #333333;
      &.textarea {
        height: 80px;
        align-items: flex-start;
        padding: 12px 7px;
      }
      .label {
        display: flex;
        align-items: center;
        .required {
          content: "";
          color: #ff0000;
          display: inline-block;
          width: 6px;
          height: 6px;
          background: url("../../assets/images/required.png") no-repeat;
          background-size: 100% 100%;
          margin-right: 4px;
        }
        .scan {
          width: 19px;
          height: 19px;
          margin-left: 9px;
        }
      }
      .info-wrap {
        flex: 1;
        margin-left: 20px;
        text-align: right;
        .code {
          color: #548af1;
        }
      }
      input {
        width: 100%;
        border: none;
        text-align: right;
      }
      .textarea {
        height: 35px;
        width: 100%;
        border: none;
        font-size: 14px;
        color: #333333;
        text-align: right;
      }
      .select-wrap {
        color: #999999;
        .val {
          color: #333333;
        }
        i {
          margin-left: 5px;
          color: #909090;
        }
      }
    }
    .remark-wrap {
      padding: 10px 15px;
    }
  }
}
.tab-box {
  .tab-hd {
    height: 37px;
    line-height: 37px;
    border-bottom: 1px #f3f3f3 solid;
    margin: 0 7px;
    font-size: 14px;
    color: #333333;
    .item {
      margin: 0 12px;
      height: 35px;
      display: inline-block;
      padding: 0 3px;
      &.active {
        color: #548af1;
        border-bottom: 2px #548af1 solid;
      }
    }
  }
}
</style>
